package com.campus.client.controller;


import com.campus.client.net.ClientConnector;
import com.campus.common.message.TeacherAccountManagementResponse;
import com.campus.common.vo.Teacher;

import java.io.IOException;
import java.util.List;

public class TeacherAccountManagementController {
    private ClientConnector connector;

    public TeacherAccountManagementController(ClientConnector connector) {
        this.connector = connector;
    }

    public List<Teacher> getTeachers() throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.listTeachers();
        return resp.getTeachers();
    }

    public boolean addTeacher(Teacher teacher) throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.addTeacher(teacher);
        return resp.isSuccess();
    }
    public boolean deleteTeacher(String id) throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.deleteTeacher(id);
        return resp.isSuccess();
    }
    public List<Teacher> searchTeachersById(String id) throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.searchTeachersById(id);
        return resp.getTeachers();
    }

    public List<Teacher> searchTeachersByName(String name) throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.searchTeachersByName(name);
        return resp.getTeachers();
    }

    public List<Teacher> searchTeachers(String title, String author) throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.searchTeachers(title, author);
        return resp.getTeachers();
    }
    public boolean updateTeacher(Teacher teacher) throws ClassNotFoundException, IOException {
        TeacherAccountManagementResponse resp = connector.updateTeachers(teacher);
        return resp.isSuccess();
    }

    // 可选：结束会话时关闭连接
    public void closeConnection() throws IOException {
        connector.close();
    }
}
